package com.uyaer.engine.display.el
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	public class BitmapAnimation extends Bitmap
	{
		protected var cache:BitmapData;
		protected var bitmap:BitmapData;
		
		private var clip:Rectangle;
		private var pos:Point=new Point(0,0);
		private var frames:Vector.<Rectangle>;
		private var index:int = 0;
		private var totalFrames:int;
		public function BitmapAnimation(bmData:BitmapData , frames:Vector.<Rectangle>)
		{
			
			this.cache = bmData;
			this.frames = frames;
			this.totalFrames = frames.length;
			
			init();
		}
		
		protected function init():void{
			bitmap = new BitmapData(frames[0].width, frames[0].height,true,0x00000000);
			this.bitmapData = bitmap;
		}
		
		public function render():void{
			if(index >= totalFrames){
				index = 0;
			}
			clip = frames[index];
			index++;
			
			bitmapData.copyPixels(cache,clip,pos);
		}
	}
}